<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Take Exam</title>
</head>
<body>

	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<div id="alluser">

	<!-- receive question index -->	
	<c:set var="qIndex" value="${param.q_index }"></c:set>
	
	<!-- receive answer id if student only edits an answer -->
	<c:set var="ansId" value="${param.aid }"></c:set>
	
	<!-- checks if student only edits an answer -->
	<c:set var="toEdit" value="${param.edit }"></c:set>
	
	<!-- receive question object -->
	<c:set var="theQuestion" value="${requestScope.question }"></c:set>
	<c:if test="${empty theQuestion}" >
		<c:redirect url="LoginServlet"></c:redirect>
	</c:if>
	
	<div class="box">
		<div class="box-header well">
			<h2><i class="icon-list-alt"></i> Question Number ${qIndex+1 }</h2>
			<div class="box-icon">
				<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
			</div>
		</div>
		
		<div class="box-content">
	
		<!-- display question -->
		<!-- display choices:radio button form -->
		<!-- submit post button forward to take exam servlet including parameter of the answer id-->
		<!-- add hidden response next index = question index + 1 -->
		<!-- add hidden question id -->
		${theQuestion.question }<br/><br/>
		<form class="form-horizontal" action="TakeExamServlet" method="post">
			<c:forEach var="choiceAns" items="${theQuestion.choices }">
				<c:choose>
					<c:when test="${(not empty ansId) and (ansId eq choiceAns.answerId) }">
					<label class="radio">
						<input type="radio" name="answer_id" value="${choiceAns.answerId }" checked="checked">${choiceAns.answer }
					</label><br/><br/>
					</c:when>
					<c:otherwise>
					<label class="radio">
						<input type="radio" name="answer_id" value="${choiceAns.answerId }">${choiceAns.answer }
					</label><br/><br/>
					</c:otherwise>
				</c:choose>
			</c:forEach>
			<input type="hidden" name="next_question_index" value="${qIndex+1 }">
			<input type="hidden" name="question_id" value="${theQuestion.questionId }">
			<c:choose>
				<c:when test="${not empty toEdit }">
					<input class="btn btn-info" type="submit" name="submit_button" value="Back to Review">
				</c:when>
				<c:otherwise>
					<input class="btn btn-info" type="submit" name="submit_button" value="Next Question">
					<input class="btn btn-danger" type="submit" name="submit_button" value="End Exam">	
				</c:otherwise>
			</c:choose>
		</form>	
	
		</div>
	
	</div>
	
	</div>
	</div>

</body>
</html>